package cn.edu.tju.elm.model;

import cn.edu.tju.core.model.BaseEntity;
import jakarta.persistence.*;

import java.math.BigDecimal;

@Entity
@Table(name = "orderdetailet")
public class OrderDetailet extends BaseEntity {
    @ManyToOne
    @JoinColumn(name = "order_id", nullable = false)
    private Order order;

    @ManyToOne
    @JoinColumn(name = "food_id", nullable = false)
    private Food food;

    private Integer quantity;
    
    // 添加商品快照字段
    @Column(length = 100)
    private String foodName; // 下单时的商品名称
    
    @Column(precision = 10, scale = 2)
    private BigDecimal foodPrice; // 下单时的商品价格
    
    @Column(length = 255)
    private String foodDescription; // 下单时的商品描述
    
    @Column(length = 500)
    private String foodImg; // 下单时的商品图片URL

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public Food getFood() {
        return food;
    }

    public void setFood(Food food) {
        this.food = food;
        // 自动设置快照字段
        if (food != null) {
            this.foodName = food.getFoodName();
            this.foodPrice = food.getFoodPrice();
            this.foodDescription = food.getFoodExplain(); // 使用foodExplain字段
            this.foodImg = food.getFoodImg();
        }
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public String getFoodName() {
        return foodName;
    }

    public void setFoodName(String foodName) {
        this.foodName = foodName;
    }

    public BigDecimal getFoodPrice() {
        return foodPrice;
    }

    public void setFoodPrice(BigDecimal foodPrice) {
        this.foodPrice = foodPrice;
    }

    public String getFoodDescription() {
        return foodDescription;
    }

    public void setFoodDescription(String foodDescription) {
        this.foodDescription = foodDescription;
    }

    public String getFoodImg() {
        return foodImg;
    }

    public void setFoodImg(String foodImg) {
        this.foodImg = foodImg;
    }
}
